﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Optum.SN.Infra.Core.Cryptography.Test.IntegrationTests
{
    /// <summary>
    /// Tests symmetric cryptography implementation.
    /// </summary>
    [TestClass]
    public class SymmetricCryptoTest
    {
        /// <summary>
        /// Tests encrypting a list of string values.
        /// </summary>
        [TestMethod]
        public void TestEncryptList()
        {
            var input = new MockData();
            var output = new SymmetricCrypto().Encrypt(input.GetPlainTextList());
            Assert.AreEqual(input.Count, output.Count);
            output.ForEach(model => Assert.IsTrue(!string.IsNullOrWhiteSpace(model.CipherText)));
            output.ForEach(model => Assert.AreEqual(48, model.CipherText.Length));
        }
        /// <summary>
        /// Tests decrypting a list of encrypted string values.
        /// </summary>
        [TestMethod]
        public void TestDecryptList()
        {
            var input = new MockData();
            var output = new SymmetricCrypto().Decrypt(input.GetCipherTextList());
            Assert.AreEqual(input.Count, output.Count);
            output.ForEach(model => Assert.IsTrue(!string.IsNullOrWhiteSpace(model.PlainText)));
            output.ForEach(model => Assert.AreEqual(11, model.PlainText.Length));
            output.ForEach(model => Assert.IsTrue(input.ContainsPlainText(model.PlainText)));
        }
        /// <summary>
        /// Tests encrypting a string value.
        /// </summary>
        [TestMethod]
        public void TestEncrypt()
        {
            var cipherText = new SymmetricCrypto().Encrypt(new MockData().MockRecord.Key);
            Assert.IsTrue(!string.IsNullOrWhiteSpace(cipherText));
            Assert.AreEqual(48, cipherText.Length);
        }
        /// <summary>
        /// Tests decrypting a string value.
        /// </summary>
        [TestMethod]
        public void TestDecrypt()
        {
            var input = new MockData().MockRecord;
            var output = new SymmetricCrypto().Decrypt(input.Value);
            Assert.AreEqual(output, input.Key);
        }
    }
}